﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RenameTool.CApRenameToolEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPAPPLICATIONLib;
using EngineeringInternalExtension;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands.RenameTool;

public class CApRenameToolEnabler : TxCommandEnabler
{
  private TxApplicationEx appEx = new TxApplicationEx();

  public CApRenameToolEnabler()
  {
    this._enable = this.ShouldEnable();
    this.RegisterToEvents();
  }

  internal void RegisterToEvents()
  {
    TxApplication.DocumentCollection.DocumentLoaded += new TxDocumentCollection_DocumentLoadedEventHandler(this.OnDocumentLoaded);
    TxApplication.ActiveDocument.Unloading += new TxDocument_UnloadingEventHandler(this.OnDocumentUnloading);
  }

  internal void UnregisterFromEvents()
  {
    TxApplication.DocumentCollection.DocumentLoaded -= new TxDocumentCollection_DocumentLoadedEventHandler(this.OnDocumentLoaded);
    TxApplication.ActiveDocument.Unloading -= new TxDocument_UnloadingEventHandler(this.OnDocumentUnloading);
  }

  private void OnDocumentLoaded(object sender, TxDocumentCollection_DocumentLoadedEventArgs args)
  {
    this._enable = this.ShouldEnable();
  }

  private void OnDocumentUnloading(object sender, TxDocument_UnloadingEventArgs args)
  {
    this._enable = this.ShouldEnable();
  }

  private bool ShouldEnable()
  {
    bool flag = false;
    if (this.appEx.IsOnLine())
      flag = ((IEmpApplication) new EmpApplicationClass()).CurrentProject.objectId != 0;
    else if (TxTcUtilities.IsTcAnyPlatform)
      flag = TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded();
    else if (TxApplication.ActiveDocument.CurrentStudy != null)
      flag = true;
    return flag;
  }
}
